home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #2
/
Amiga Plus CD - 2004 - No. 02.iso
/
AmiSoft
/
Gfx
/
conv
/
GIFsplit.lha
/
source
/
GIFsplit.ab2
next >
Wrap
Text File
|
2004-01-21
|
7KB
|
198 lines
; GifSplit (Blitz) v1.0b GNU Copyright (C) 2003-2004 Lorence Lombardo.
; This program is Free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY OR FITNESS For A PARTICULAR PURPOSE. See the
; GNU General Public License For more details.
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; GifSplit (Blitz) was based on GifSplit.rexx by Bryan K. Williams
; which has been translated, optimized and re-written.
; GIFsplit does not use any LZW patented algorithm.
F$=Par$(1): l$=Chr$(10): np=NumPars: vb=0: dg=4: p3$=UCase$(Par$(3)): p4$=UCase$(Par$(4))
If np=0 OR F$="?" Then Goto usage
If np>2 AND p3$="V" Then vb=1
If np>3 AND p4$="V" Then vb=1
If np>2 AND Left$(p3$,1)="D" Then dg=Val(Mid$(p3$,2))
If np>3 AND Left$(p4$,1)="D" Then dg=Val(Mid$(p4$,2))
fm$=String$("0",dg)
If ReadFile(0,F$)
; Read GIF's dimensions.
FileInput 0: hed$=Inkey$(6)
If hed$<>"GIF89a" AND hed$<>"GIF87a" Then NPrint l$,F$," file is not a GIF.",l$: End
gdim$=Inkey$(7)
width=c2d(StrFlip(Mid$(gdim$,1,2)))
height=c2d(StrFlip(Mid$(gdim$,3,2)))
stuff=c2d(Mid$(gdim$,5,1)): stuff$=Right$(Bin$(stuff),8)
GBC=Val(Left$(stuff$,1))
colres=Val("%"+Mid$(stuff$,2,3))+1
totalpal.l=(2^colres)^3
sortf=Val(Mid$(stuff$,5,1)) ; sort flag
SOT=Val("%"+Right$(stuff$,3))+1 ; size of table
backgrd = c2d(Mid$(gdim$,6,1))
ratio = c2d(Mid$(gdim$,7,1))
If ratio=0 Then ratio=1
hed$=hed$+gdim$
NPrint l$,"Screen Width : ",width
NPrint "Screen Height : ",height
If GBC NPrint "Global Color Map : Yes" Else NPrint "Global Color Map : No"
NPrint "Color Resolution : ",colres," bits (",totalpal," Total Palette)"
If sortf NPrint "Palette sorted by decreasing importance" Else NPrint "Palette unsorted"
NPrint "Bitplanes : ",SOT," (",2^SOT," colors)"
NPrint "Background color : #",backgrd
NPrint "Pixel Ratio : ",ratio,l$
;read global color table (maybe)
;3 bytes * 2^bitplates
gct$="": Format "000"
If GBC=1
If vb=1 Then NPrint "Reading global color table"
gct$=Inkey$(3*(2^SOT))
If vb=1
For x=1 To (2^SOT) Step 2
out$=" Color "+Str$(x)+" RGB "+Right$(c2x(Mid$(gct$,(x-1)*3+1,3)),6)
out$=out$+" Color "+Str$(x+1)+" RGB "+Right$(c2x(Mid$(gct$,x*3+1,3)),6)
NPrint out$
Next x
EndIf
EndIf
;Getting ready To split files.
fcount.l=1: NPrint "": fstart$=Par$(2): If np<2 Then fstart$=""
While NOT Eof(0)
nx$=Inkey$: nx=Asc(nx$)
While nx<>$2C AND nx<>$3B
If nx=$21
If vb=1 Then NPrint "Gif Extension code"
bltype=Asc(Inkey$): lenn=c2d(Inkey$)
If vb=1
Select bltype
Case $F9: NPrint "Graphic Control Extension"
Case $FE: NPrint "Comment Extension"
Case $01: NPrint "Play Text Extension"
Case $FF: NPrint "Application Extension"
Default : NPrint "Unknown Extension of hex type ",Right$(Hex$(bltype),2)
End Select
NPrint ""
EndIf
bla$=Inkey$(lenn) ; Application Extension Type
If bltype=$FF
BlkLen = c2d(Inkey$) ; Read Length of extension Type
bla$=Inkey$(BlkLen) ; Read Application Extension Data
EndIf
ending=Asc(Inkey$)
If ending<>0 Then NPrint "No data terminator for this block, exiting...",l$: End
Else
NPrint "Somethings wrong. Hex character ",c2x(nx$)," found. Exiting...",l$
End
EndIf
nx$=Inkey$: nx=Asc(nx$)
Wend
If nx=$3B Then NPrint "File termination found, exiting...",l$: CloseFile 0: End
Format fm$: NPrint Chr$(11)+"Found image number ",fcount: Format ""
codehed$ = nx$+Inkey$(9)
imageleft = c2d(StrFlip(Mid$(codehed$,2,2)))
imagetop = c2d(StrFlip(Mid$(codehed$,4,2)))
imagewidth = c2d(StrFlip(Mid$(codehed$,6,2)))
imageheight = c2d(StrFlip(Mid$(codehed$,8,2)))
stuff = c2d(Right$(codehed$,1)): stuff$=Right$(Bin$(stuff),8)
localcolor = Val(Left$(stuff$,1))
interlace = Val(Mid$(stuff$,2,1))
localsortflag = Val(Mid$(stuff$,3,1))
localcolortable = Val("%"+Right$(stuff$,3))+1
If vb=1
NPrint "Image Left : ",imageleft
NPrint "Image Top : ",imagetop
NPrint "Image Width : ",imagewidth
NPrint "Image Height: ",imageheight
If localcolor NPrint "Local Color Table : Yes" Else NPrint "Local Color Table : No"
If interlace NPrint "Interlaced" Else NPrint "Not Interlaced"
If localSortflag NPrint "Palette sorted by decreasing importance" Else NPrint "Palette unsorted"
EndIf
lct$="": Format "000"
If localcolor=1
If vb=1 Then NPrint "Reading local color table"
lct$=Inkey$(3*(2^localcolortable))
If vb=1
For x = 1 To (2^localcolortable) Step 2
out$=" Color "+Str$(x)+" RGB "+Right$(c2x(Mid$(lct$,(x-1)*3+1,3)),6)
out$=out$+" Color "+Str$(x+1)+" RGB "+Right$(c2x(Mid$(lct$,x*3+1,3)),6)
NPrint out$
Next x
EndIf
EndIf
code$=Inkey$: codesize$=Inkey$
code$=code$+codesize$: chsz = c2d(codesize$)
Format fm$: fout$=fstart$+Str$(fcount)
If WriteFile (1,fout$)
FileOutput 1: Print hed$+gct$+codehed$+lct$
While chsz>0 AND NOT Eof(0)
code$=code$+Inkey$(chsz): Print code$
code$=Inkey$: chsz = c2d(code$)
Wend
Print code$: DefaultOutput: CloseFile 1
If vb=1 Then NPrint "End of image.",l$
Else
NPrint l$,"Could not output files.",l$: End
EndIf
fcount+1
Wend
Else
NPrint l$,F$," file not found.",l$: End
EndIf
NPrint l$,"??? Premature EOF ???",l$: CloseFile 0: End
usage:
NPrint l$," GifSplit (Blitz) v1.0b GNU (C) 2003-2004 Lorence Lombardo.",l$
NPrint " Usage:- GifSplit infile outfile [V=VERBOSE] [D#=DIGIT#]"
NPrint " eg. GifSplit GifAnim.GIF Pic. D6",l$
End